const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const User = require('./User');

const FavoriteLocation = sequelize.define('FavoriteLocation', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: User,
      key: 'id'
    }
  },
  location: {
    type: DataTypes.STRING,
    allowNull: false
  },
  latitude: {
    type: DataTypes.FLOAT,
    allowNull: false
  },
  longitude: {
    type: DataTypes.FLOAT,
    allowNull: false
  }
}, {
  timestamps: true
});

// 建立关联关系
FavoriteLocation.belongsTo(User, { foreignKey: 'userId' });
User.hasMany(FavoriteLocation, { foreignKey: 'userId' });

module.exports = FavoriteLocation; 